package org.fanrui.hrm.service.impl;

import org.apache.commons.lang.time.DateUtils;
import org.fanrui.hrm.constants.meal.MealConstants;
import org.fanrui.hrm.domain.Meal;
import org.fanrui.hrm.mapper.MealMapper;
import org.fanrui.hrm.service.IMealService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * 套餐表 服务实现类
 * </p>
 *
 * @author fanrui
 * @since 2024-09-12
 */
@Service
public class MealServiceImpl extends ServiceImpl<MealMapper, Meal> implements IMealService {

    @Autowired
    private MealMapper mealMapper;

    /**
     * 保存套餐和登录关系 t_meal_login
     *
     * @param loginId 登录id
     * @param mealId  套餐id
     */
    @Override
    public void saveRelationWidthLogin(Long loginId, Long mealId) {
        try {
            // 保存套餐和登录关系
            Date expireTime = DateUtils.addDays(new Date(), 7);
            /**
             * 套餐状态：0：未支付，1：已支付，2：已过期
             * 默认为未支付
             */
            mealMapper.saveRelationWidthLogin(loginId, mealId, expireTime, MealConstants.STATE_UN_PAY);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
